package cn.xiaobai.utils.module;

import cn.xiaobai.utils.YamlUtils;
import lombok.extern.slf4j.Slf4j;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author yangdaji
 * @date 2022/6/27
 */
@Deprecated
@Slf4j
public class YamlProperty {



    /**
     * 配置文件k,v
     */
    private LinkedHashMap<String, Object> load;

    public YamlProperty(String sourcePath) {
        try {
            Yaml yaml = new Yaml();
            load = yaml.loadAs(new FileInputStream(sourcePath), LinkedHashMap.class);
        } catch (FileNotFoundException e) {
            log.info(String.format("加载文件失败: %s", e.getLocalizedMessage()));
        }
    }

    /**
     * 获取配置文件属性值
     *
     * @param property 属性名称
     */
    public String getValue(String property) {
        return YamlUtils.getYmlProperty(load, property);
    }

    /**
     * 获取配置文件属性值
     *
     * @param property 属性名称
     */
    public Map<String, Object> getValueMap(String... property) {
        Map<String, Object> map = new HashMap<>();
        for (String key : property) {
            String value = getValue(key);
            map.put(key, value);
        }
        return map;
    }


}
